package com.zj.weather.utils;

import java.lang.reflect.Field;

import com.zj.weather.R;

/**
 * Created by zhaojie on 2017/4/19.
 */

public class StaticValue {

    //key为server端返回的天气类型
    public static int getWeatherTimeBg(int key) {
        String title = "d_bg_" + key;
        if (!isDay())
            title = "n_bg_" + key;
        return getResId(title, R.drawable.class);
    }

    public static boolean isDay() {
        int hour = 12;
        int sunRise = 19;
        int sunSet = 6;
        if (hour <= sunRise && hour >= sunSet)
            return true;
        else
            return false;
    }

    public static int getResId(String variableName, Class<?> c) {
        try {
            Field idField = c.getDeclaredField(variableName);
            return idField.getInt(idField);
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }
}
